package com.yangcangclub.commons.utils;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;



/**
 * @author 字符串工具类
 */
public class StringUtil {
    /**
     * 检查特殊字符
     * @author tian
     */
    private static String regEx="[`~!@#$%&*()={}':;'\\[\\]<>/?~！@#￥%……&*（）——+{}【】‘；：”“’。，、？]";
    public   static   boolean StringCheck(String   str) {
        return   Pattern.compile(regEx).matcher(str).find();
    }


    /**
     * 检查手机号码(支持国际手机号)是否合法
     * @author tian
     */
    public   static   boolean checkPhoneNo(String   phoneNo) {
        if (!phoneNo.contains("-"))
            phoneNo="0086-"+phoneNo;

        //中国
        if(phoneNo.startsWith("0086-")||!phoneNo.contains("-"))  return Pattern.compile("^1[3|4|5|6|7|8|9][0-9]{9}$").matcher(phoneNo.replace("0086-", "")).find();
        //中国香港
        if(phoneNo.startsWith("00852-"))  return Pattern.compile("^[569]\\d{7}$").matcher(phoneNo.replace("00852-", "")).find();
        //中国澳门
        if(phoneNo.startsWith("00853-"))  return Pattern.compile("^6\\d{7}$").matcher(phoneNo.replace("00853-", "")).find();
        //中国台湾
        if(phoneNo.startsWith("00886-"))  return Pattern.compile("^9\\d{8}$").matcher(phoneNo.replace("00886-", "")).find();
        //美国，加拿大
        if(phoneNo.startsWith("001-"))  return Pattern.compile("^\\d{10}$").matcher(phoneNo.replace("001-", "")).find();
        //马来西亚
        if(phoneNo.startsWith("0060-"))  return Pattern.compile("^1\\d{8}$").matcher(phoneNo.replace("0060-", "")).find();
        //澳洲
        if(phoneNo.startsWith("0061-"))  return Pattern.compile("^4\\d{8}$").matcher(phoneNo.replace("0061-", "")).find();
        //日本
        if(phoneNo.startsWith("0081-"))  return Pattern.compile("^[789]0\\d{8}$").matcher(phoneNo.replace("0081-", "")).find();
        //韩国
        if(phoneNo.startsWith("0082-"))  return Pattern.compile("^1[016789]\\d{8}$").matcher(phoneNo.replace("0082-", "")).find();
        //新加坡
        if(phoneNo.startsWith("0065-"))  return Pattern.compile("^[89]\\d{7}$").matcher(phoneNo.replace("0065-", "")).find();
        //英国
        if(phoneNo.startsWith("0044-"))  return Pattern.compile("^(7[45789]\\d{8})|7624\\d{6}$").matcher(phoneNo.replace("0044-", "")).find();
        //法国
        if(phoneNo.startsWith("0033-"))  return Pattern.compile("^((6\\d{8})|(7[345678]\\d{7}))$").matcher(phoneNo.replace("0033-", "")).find();
        //俄罗斯
        if(phoneNo.startsWith("007-"))  return Pattern.compile("^((90[12345689]\\d{7})|(9[1236]\\d{8})|(95[0123]\\d{7}))$").matcher(phoneNo.replace("007-", "")).find();
        //印度
        if(phoneNo.startsWith("0091-"))  return Pattern.compile("^[987]\\d{9}$").matcher(phoneNo.replace("0091-", "")).find();
        //泰国
        if(phoneNo.startsWith("0066-"))  return Pattern.compile("^[98]\\d{8}$").matcher(phoneNo.replace("0066-", "")).find();
        //德国
        if(phoneNo.startsWith("0049-"))  return Pattern.compile("^(15[12579]\\d{7}|16[023]\\d{7}|160\\d{8}|17[012345789]\\d{7}|176\\d{8}|700\\d{8})$").matcher(phoneNo.replace("0049-", "")).find();

        return false;

    }


    public  static   String splitPhoneNumber(String   phoneNo) {

        if(phoneNo.startsWith("86")) {
            phoneNo=phoneNo.substring(2,phoneNo.length());
        } else if(phoneNo.startsWith("852")) {
            phoneNo=phoneNo.substring(3,phoneNo.length());
        }else if(phoneNo.startsWith("853")) {
            phoneNo=phoneNo.substring(3,phoneNo.length());
        }else if(phoneNo.startsWith("886")) {
            phoneNo=phoneNo.substring(3,phoneNo.length());
        }else if(phoneNo.startsWith("1")) {
            phoneNo=phoneNo.substring(1,phoneNo.length());
        }else if(phoneNo.startsWith("60")) {
            phoneNo=phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("61")) {
            phoneNo=phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("81")) {
            phoneNo=phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("82")) {
            phoneNo=phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("65")) {
            phoneNo=phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("44")) {
            phoneNo=phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("33")) {
            phoneNo=phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("7")) {
            phoneNo=phoneNo.substring(1,phoneNo.length());
        }else if(phoneNo.startsWith("91")) {
            phoneNo=phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("66")) {
            phoneNo=phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("49")) {
            phoneNo=phoneNo.substring(2,phoneNo.length());
        }

        return phoneNo;
    }


    /**
     * 检查手机号码(支持国际手机号)是否合法
     * @author tian
     */
    public   static   boolean checkPhoneNumber(String   phoneNo) {

//        if(phoneNo.startsWith("+86")) {
//            phoneNo="0086-"+phoneNo.substring(3,phoneNo.length());
//        } else if(phoneNo.startsWith("+852")) {
//            phoneNo="00852-"+phoneNo.substring(4,phoneNo.length());
//        }else if(phoneNo.startsWith("+853")) {
//            phoneNo="00853-"+phoneNo.substring(4,phoneNo.length());
//        }else if(phoneNo.startsWith("+886")) {
//            phoneNo="00856-"+phoneNo.substring(4,phoneNo.length());
//        }else if(phoneNo.startsWith("+1")) {
//            phoneNo="001-"+phoneNo.substring(2,phoneNo.length());
//        }else if(phoneNo.startsWith("+60")) {
//            phoneNo="0060-"+phoneNo.substring(3,phoneNo.length());
//        }else if(phoneNo.startsWith("+61")) {
//            phoneNo="0061-"+phoneNo.substring(3,phoneNo.length());
//        }else if(phoneNo.startsWith("+81")) {
//            phoneNo="0081-"+phoneNo.substring(3,phoneNo.length());
//        }else if(phoneNo.startsWith("+82")) {
//            phoneNo="0082-"+phoneNo.substring(3,phoneNo.length());
//        }else if(phoneNo.startsWith("+65")) {
//            phoneNo="0065-"+phoneNo.substring(3,phoneNo.length());
//        }else if(phoneNo.startsWith("+44")) {
//            phoneNo="0044-"+phoneNo.substring(3,phoneNo.length());
//        }else if(phoneNo.startsWith("+33")) {
//            phoneNo="0033-"+phoneNo.substring(3,phoneNo.length());
//        }else if(phoneNo.startsWith("+7")) {
//            phoneNo="007-"+phoneNo.substring(2,phoneNo.length());
//        }else if(phoneNo.startsWith("+91")) {
//            phoneNo="0091-"+phoneNo.substring(3,phoneNo.length());
//        }else if(phoneNo.startsWith("+66")) {
//            phoneNo="0066-"+phoneNo.substring(3,phoneNo.length());
//        }else if(phoneNo.startsWith("+49")) {
//            phoneNo="0049-"+phoneNo.substring(3,phoneNo.length());
//        }


        if(phoneNo.startsWith("86")) {
            phoneNo="0086-"+phoneNo.substring(2,phoneNo.length());
        } else if(phoneNo.startsWith("852")) {
            phoneNo="00852-"+phoneNo.substring(3,phoneNo.length());
        }else if(phoneNo.startsWith("853")) {
            phoneNo="00853-"+phoneNo.substring(3,phoneNo.length());
        }else if(phoneNo.startsWith("886")) {
            phoneNo="00856-"+phoneNo.substring(3,phoneNo.length());
        }else if(phoneNo.startsWith("1")) {
            phoneNo="001-"+phoneNo.substring(1,phoneNo.length());
        }else if(phoneNo.startsWith("60")) {
            phoneNo="0060-"+phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("61")) {
            phoneNo="0061-"+phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("81")) {
            phoneNo="0081-"+phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("82")) {
            phoneNo="0082-"+phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("65")) {
            phoneNo="0065-"+phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("44")) {
            phoneNo="0044-"+phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("33")) {
            phoneNo="0033-"+phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("7")) {
            phoneNo="007-"+phoneNo.substring(1,phoneNo.length());
        }else if(phoneNo.startsWith("91")) {
            phoneNo="0091-"+phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("66")) {
            phoneNo="0066-"+phoneNo.substring(2,phoneNo.length());
        }else if(phoneNo.startsWith("49")) {
            phoneNo="0049-"+phoneNo.substring(2,phoneNo.length());
        }

        //中国
        if(phoneNo.startsWith("0086-")||!phoneNo.contains("-"))  return Pattern.compile("^1[3|4|5|6|7|8|9][0-9]{9}$").matcher(phoneNo.replace("0086-", "")).find();
        //中国香港
        if(phoneNo.startsWith("00852-"))  return Pattern.compile("^[569]\\d{7}$").matcher(phoneNo.replace("00852-", "")).find();
        //中国澳门
        if(phoneNo.startsWith("00853-"))  return Pattern.compile("^6\\d{7}$").matcher(phoneNo.replace("00853-", "")).find();
        //中国台湾
        if(phoneNo.startsWith("00886-"))  return Pattern.compile("^9\\d{8}$").matcher(phoneNo.replace("00886-", "")).find();
        //美国，加拿大
        if(phoneNo.startsWith("001-"))  return Pattern.compile("^\\d{10}$").matcher(phoneNo.replace("001-", "")).find();
        //马来西亚
        if(phoneNo.startsWith("0060-"))  return Pattern.compile("^1\\d{8}$").matcher(phoneNo.replace("0060-", "")).find();
        //澳洲
        if(phoneNo.startsWith("0061-"))  return Pattern.compile("^4\\d{8}$").matcher(phoneNo.replace("0061-", "")).find();
        //日本
        if(phoneNo.startsWith("0081-"))  return Pattern.compile("^[789]0\\d{8}$").matcher(phoneNo.replace("0081-", "")).find();
        //韩国
        if(phoneNo.startsWith("0082-"))  return Pattern.compile("^1[016789]\\d{8}$").matcher(phoneNo.replace("0082-", "")).find();
        //新加坡
        if(phoneNo.startsWith("0065-"))  return Pattern.compile("^[89]\\d{7}$").matcher(phoneNo.replace("0065-", "")).find();
        //英国
        if(phoneNo.startsWith("0044-"))  return Pattern.compile("^(7[45789]\\d{8})|7624\\d{6}$").matcher(phoneNo.replace("0044-", "")).find();
        //法国
        if(phoneNo.startsWith("0033-"))  return Pattern.compile("^((6\\d{8})|(7[345678]\\d{7}))$").matcher(phoneNo.replace("0033-", "")).find();
        //俄罗斯
        if(phoneNo.startsWith("007-"))  return Pattern.compile("^((90[12345689]\\d{7})|(9[1236]\\d{8})|(95[0123]\\d{7}))$").matcher(phoneNo.replace("007-", "")).find();
        //印度
        if(phoneNo.startsWith("0091-"))  return Pattern.compile("^[987]\\d{9}$").matcher(phoneNo.replace("0091-", "")).find();
        //泰国
        if(phoneNo.startsWith("0066-"))  return Pattern.compile("^[98]\\d{8}$").matcher(phoneNo.replace("0066-", "")).find();
        //德国
        if(phoneNo.startsWith("0049-"))  return Pattern.compile("^(15[12579]\\d{7}|16[023]\\d{7}|160\\d{8}|17[012345789]\\d{7}|176\\d{8}|700\\d{8})$").matcher(phoneNo.replace("0049-", "")).find();

        return false;

    }


    /*
     * 昵称校验
     * 只能为数字，字母，下划线_ ,横杠-。长度不超过20
     */
    public   static   boolean checkNickName(String   str) {
        if(str.length()>20)return false;
        str=str.replace("-", "");
        str=str.replace("_", "");
        return   Pattern.compile("^[a-zA-Z0-9]+$").matcher(str).find();
    }

    /**
     * 只能为数字或字母
     * @author tian
     */
    private static String onlyNoLetter="^[a-zA-Z0-9]+$";
    public   static   boolean onlyNoLetter(String   str) {
        return   Pattern.compile(onlyNoLetter).matcher(str).find();
    }
    /**
     * 非空判断
     * @author
     * @param str
     * @return
     */
    public static boolean isEmpty(String str) {
        return (str == null) || (str.length() == 0);
    }

    /**
     * 宽泛校验
     * 非空判断  排除字符串“null”
     */
    public static boolean isFullEmpty(String str) {
        return (str == null) || (str.trim().length() == 0)||"null".equalsIgnoreCase(str);
    }

    /**
     * 宽泛校验
     * 非空判断  排除字符串“null”, 和带空格的“ null ” 
     */
    public static boolean isAllFullEmpty(String str) {
        return (str == null) || (str.trim().length() == 0)||"null".equalsIgnoreCase(str.trim());
    }

    /**
     * 宽泛校验
     * 非空判断  排除字符串“null”
     */
    public static boolean isNotEmpty(String str) {
        return  ! isFullEmpty(str);
    }

    public static boolean hasDouHaoAndAllNumber(String str) {
        if(! isFullEmpty(str)) {
            String[] tempStringArray = splitAll(str,",");
            if(null!=tempStringArray&&tempStringArray.length>0) {
                boolean falg = true;
                for (int i=0;i<tempStringArray.length;i++) {
                    if(isNotNumber(tempStringArray[i])) {
                        falg = false;
                        break;
                    }
                }
                if(falg) {
                    return true;
                }
            }
        }

        return  false;
    }

    public static List<Integer> convertStringToList(String str) {
        List<Integer> idList = Lists.newArrayList();
        if(StringUtil.isNotEmpty(str)&&hasDouHaoAndAllNumber(str)) {
            String[] idsArray = StringUtil.splitAll(str, ",");
            if(null!=idsArray&&idsArray.length>0) {
                for (int i=0;i<idsArray.length;i++) {
                    idList.add(Integer.valueOf(idsArray[i]));
                }
            }
        }
        return  idList;
    }


    /**
     * 判断字符串是否符合时间格式yyyy-MM-dd
     */
    private static String yyyyMMddFmt = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
    public static boolean checkDateFormat(String date){
        boolean isValidDateStr = false;
        Pattern p = Pattern.compile(yyyyMMddFmt);
        if (p.matcher(date).matches()) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD");
            try {
                sdf.parse(date);
                isValidDateStr = true;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return isValidDateStr;
    }
    /**
     * 注册邮箱校验
     */
    private static String  check="^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$";
    public static boolean checkEmail(String email){
        boolean flag = false;
        try{
            Pattern regex = Pattern.compile(check);
            Matcher matcher = regex.matcher(email);
            flag = matcher.matches();
        }catch(Exception e){
            flag = false;
        }
        return flag;
    }



    /**
     * 判断字符是否中文汉字和符号
     * @param strName
     * @return
     */
    public static boolean isChinese(String strName) {
        char[] ch = strName.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            char c = ch[i];
            if (isChinese(c)) {
                return true;
            }
        }
        return false;
    }
    // 根据Unicode编码完美的判断中文汉字和符号
    private static boolean isChinese(char c) {
        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
        if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
                || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
                || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
                || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
                || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION) {
            return true;
        }
        return false;
    }


    /**
     * 获取登陆用户的用户名类型
     *  type  1---邮箱,2--手机,3--昵称
     */
    public static int getUserAccountType(String accout){
        if(StringUtil.checkEmail(accout))return 1;
        if(StringUtil.checkPhoneNumber(accout))return 2;
        if(Pattern.compile("^00\\d{1,4}-\\d{4,15}$").matcher(accout).find())return -1;
        if(StringUtil.checkNickName(accout))return 3;
        return -1;
    }


    //随机字母
    private static   String keyCode = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    public static  String getRandomStr(int lenth){
        char [] code=keyCode.toCharArray();
        StringBuffer str=new StringBuffer();
        Random r = new Random();
        for(int i=0;i<lenth;i++){
            str.append( code[r.nextInt(code.length-1)]);
        }
        return str.toString() ;
    }

    public static boolean isNotNumber(String str){
        return !isNumber(str);
    }
    /**
     * 判断字符串是否是数字
     * @param str
     * @return boolean
     */
    public static boolean isNumber(String str) {
        if (StringUtil.isEmpty(str)) {
            return false;
        }
        char[] chars = str.toCharArray();
        int sz = chars.length;
        boolean hasExp = false;
        boolean hasDecPoint = false;
        boolean allowSigns = false;
        boolean foundDigit = false;

        int start = chars[0] == '-' ? 1 : 0;
        if ((sz > start + 1) && (chars[start] == '0')
                && (chars[(start + 1)] == 'x')) {
            int i = start + 2;
            if (i == sz) {
                return false;
            }
            do {
                if (((chars[i] < '0') || (chars[i] > '9'))
                        && ((chars[i] < 'a') || (chars[i] > 'f'))
                        && ((chars[i] < 'A') || (chars[i] > 'F')))
                    return false;
                i++;
            } while (i < chars.length);
            return true;
        }
        sz--;
        int i = start;
        while ((i < sz) || ((i < sz + 1) && (allowSigns) && (!foundDigit))) {
            if ((chars[i] >= '0') && (chars[i] <= '9')) {
                foundDigit = true;
                allowSigns = false;
            } else if (chars[i] == '.') {
                if ((hasDecPoint) || (hasExp)) {
                    return false;
                }
                hasDecPoint = true;
            } else if ((chars[i] == 'e') || (chars[i] == 'E')) {
                if (hasExp) {
                    return false;
                }
                if (!foundDigit) {
                    return false;
                }
                hasExp = true;
                allowSigns = true;
            } else if ((chars[i] == '+') || (chars[i] == '-')) {
                if (!allowSigns) {
                    return false;
                }
                allowSigns = false;
                foundDigit = false;
            } else {
                return false;
            }
            i++;
        }
        if (i < chars.length) {
            if ((chars[i] >= '0') && (chars[i] <= '9')) {
                return true;
            }
            if ((chars[i] == 'e') || (chars[i] == 'E')) {
                return false;
            }
            if (chars[i] == '.') {
                if ((hasDecPoint) || (hasExp)) {
                    return false;
                }
                return foundDigit;
            }
            if ((!allowSigns)
                    && ((chars[i] == 'd') || (chars[i] == 'D')
                    || (chars[i] == 'f') || (chars[i] == 'F'))) {
                return foundDigit;
            }
            if ((chars[i] == 'l') || (chars[i] == 'L')) {
                return (foundDigit) && (!hasExp) && (!hasDecPoint);
            }
            return false;
        }
        return (!allowSigns) && (foundDigit);
    }
    /**
     * 生成num位随机数字
     *
     */
    public static String  getRandomNum(int num){
        StringBuilder str = new StringBuilder();
        for(int i=0;i<num;i++){
            str.append(new Random().nextInt(10));
        }
        return  str.toString();
    }


    /**
     * 过滤xss攻击字符
     */

    public static  String filterXSS(String value){
        if (value != null)
        {
            // NOTE: It's highly recommended to use the ESAPI library and uncomment the following line to
            // avoid encoded attacks.
            // value = ESAPI.encoder().canonicalize(value);
            // Avoid null characters
            value = value.replaceAll("", "");
            // Avoid anything between script tags
            Pattern scriptPattern = Pattern.compile("<script>(.*?)</script>", Pattern.CASE_INSENSITIVE);
            value = scriptPattern.matcher(value).replaceAll("");
            // Avoid anything in a src='...' type of expression
            scriptPattern = Pattern.compile("src[\r\n]*=[\r\n]*\\\'(.*?)\\\'", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
            value = scriptPattern.matcher(value).replaceAll("");
            scriptPattern = Pattern.compile("src[\r\n]*=[\r\n]*\\\"(.*?)\\\"", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
            value = scriptPattern.matcher(value).replaceAll("");
            // Remove any lonesome </script> tag
            scriptPattern = Pattern.compile("</script>", Pattern.CASE_INSENSITIVE);
            value = scriptPattern.matcher(value).replaceAll("");
            // Remove any lonesome <script ...> tag
            scriptPattern = Pattern.compile("<script(.*?)>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
            value = scriptPattern.matcher(value).replaceAll("");
            // Avoid eval(...) expressions
            scriptPattern = Pattern.compile("eval\\((.*?)\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
            value = scriptPattern.matcher(value).replaceAll("");
            // Avoid expression(...) expressions
            scriptPattern = Pattern.compile("expression\\((.*?)\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
            value = scriptPattern.matcher(value).replaceAll("");
            // Avoid javascript:... expressions
            scriptPattern = Pattern.compile("javascript:", Pattern.CASE_INSENSITIVE);
            value = scriptPattern.matcher(value).replaceAll("");
            // Avoid vbscript:... expressions
            scriptPattern = Pattern.compile("vbscript:", Pattern.CASE_INSENSITIVE);
            value = scriptPattern.matcher(value).replaceAll("");
            // Avoid onload= expressions
            scriptPattern = Pattern.compile("onload(.*?)=", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
            value = scriptPattern.matcher(value).replaceAll("");

            scriptPattern = Pattern.compile("<iframe>(.*?)</iframe>", Pattern.CASE_INSENSITIVE);
            value = scriptPattern.matcher(value).replaceAll("");

            scriptPattern = Pattern.compile("</iframe>", Pattern.CASE_INSENSITIVE);
            value = scriptPattern.matcher(value).replaceAll("");
            // Remove any lonesome <script ...> tag
            scriptPattern = Pattern.compile("<iframe(.*?)>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
            value = scriptPattern.matcher(value).replaceAll("");
        }
        return value;
    }

    public static boolean isEquals(String s1, String s2) {
        if (s1 == null && s2 == null)
            return true;
        if (s1 == null || s2 == null)
            return false;
        return s1.equalsIgnoreCase(s2);
    }

    public static String[] splitAll(String toSplit, String delimiter) {
        if (!isNotEmpty(toSplit) || !isNotEmpty(delimiter)) {
            return null;
        }
        int offset = toSplit.indexOf(delimiter);
        String[] returnaStr = null;
        if (offset < 0) {
            returnaStr =new String[1];
            returnaStr[0] =toSplit;
            return returnaStr;
        }
        List<String> splitList = new ArrayList<String>();
        String[] str =  toSplit.split(delimiter);
        for (String string : str) {
            if (isNotEmpty(string) && isNotEmpty(string)) {
                splitList.add(string);
            }
        }
        String[] returnStr = null;
        if(splitList.size() > 0) {
            returnStr = new String[splitList.size()];
            for (int i=0;i<splitList.size();i++) {
                returnStr[i] = splitList.get(i);
            }
        }
        return returnStr;
    }

    /**
     * 返回非 null string
     * @return "" if o==null;other wise o.toString
     */
    public static String toNonNullString(Object b){
        if(b==null) return "";
        if(b instanceof String) return (String)b;
        return b.toString();
    }


    /**
     * 获取字符串的时间，
     * @param intDate  20161212
     * @return  2016-12-12
     */
    public static String getYYYYMMDDFromInt(int intDate){ 
        String strDate=intDate+"";
        StringBuffer sb=new StringBuffer();
        char[] chs=strDate.toCharArray();
        for(int i=0;i<chs.length;i++){
            sb.append(chs[i]);
            if(i==3||i==5){sb.append("-");}
        }
        return sb.toString();
    }

    /**
     * 多值非空校验，使用的是 {@code isAllFullEmpty()}
     * @return
     */
    public static boolean isAllValueContainEmpty(String... values){
        if(values==null||values.length==0) throw new RuntimeException("This Method Needs Params!");
        for(String str:values)
            if(isAllFullEmpty(str)) return true;
        return false;
    }

    public static void main(String[] args) {
        System.out.println(isAllValueContainEmpty());

    }
}

